﻿using Business;
using Model;
using Public;
using Public.Tools;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web.Http;
using wochu.DPS.API.Infrastructure;

namespace wochu.DPS.API.Controllers
{
    public class SaleorderlackController : ApiController
    {
        private static BOrder _NewInstance = new BOrder();
        public static BOrder NewInstance
        {
            get
            {
                if (_NewInstance == null)
                {
                    _NewInstance = new BOrder();
                }
                return _NewInstance;
            }
        }

        /// <summary>
        /// 获取销售订单明细
        /// </summary>
        /// <param name="orderNo">订单编号</param>
        /// <returns></returns>
        [HttpGet]
        public HttpResponseMessage GetLacksaleOrder(string orderNo)
        {
            SysSetting sysSet = new SysSetting();
            if (string.IsNullOrEmpty(orderNo))
            {
                sysSet.Key = Consts.strFalse;
                sysSet.Value = "参数为NULL";
                return ResultsExtensions.GetFailJson(sysSet);
            }
            try
            {
                var data = _NewInstance.Getsaleorderinfo(orderNo);
                if (data == null || data.Count <= 0)
                {
                    sysSet.Key = Consts.strFalse;
                    sysSet.Value = "无关联信息";
                    return ResultsExtensions.GetFailJson(sysSet);
                }
                return ResultsExtensions.GetSuccessJson(data);
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                sysSet.Key = Consts.strFalse;
                sysSet.Value = " 获取信息失败，请查看日志";
                return ResultsExtensions.GetFailJson(sysSet);
            }
        }

        [HttpPost]
        public HttpResponseMessage Lack_SaleOrderInfo(List<Saleorderlackinfo> SaleOrderInfo, int operationUser)
        {
            string message = "";
            SysSetting sysSet = new SysSetting();
            if (SaleOrderInfo == null||SaleOrderInfo.Count <= 0 )
            {
                sysSet.Key = Consts.strFalse;
                sysSet.Value = "参数为NULL";
                return ResultsExtensions.GetFailJson(sysSet);
            }
            if (NewInstance.SetLacksaleorderinfo(out  message, SaleOrderInfo, operationUser))
                return ResultsExtensions.GetSuccessJson(true);
            else
            {
                SysSetting syserr = new SysSetting() { Key = "0", Value = message };
                return ResultsExtensions.GetFailJson(syserr);
            }
        }



    }
}